<template>
  <NuxtLayout>
    <NuxtPage/>
  </NuxtLayout>
</template>
<script setup lang="ts">
import {getSiteConfig} from "~/server/system.service";
import {fixedTop} from "~/utils/CommonUtil";
import system from "~/config/SystemConfig";
import {auth} from "~/service/auth.service";
import Cookie from "js-cookie"

const appStore = useAppStore()
onBeforeMount(async () => {
  await getSite()
  await initAPP()
  appStore.initializeTheme()
  fixedTop()
})
// onMounted(() => {
//   noticePopup()
// })
//
// function noticePopup() {
//   if (!Cookie.get('popupShow')) {
//     auth.updatePopup({
//       confirm: () => {
//         Cookie.set('popupShow', 'show', {expires: 7, path: '/'})
//         auth.destroyDiv('updatePopup')
//       },
//       // cancel:()=>{
//       //     Cookie.set('popupShow','show',{ expires: 0.1, path: '/' })
//       // }
//     })
//   }
// }

function initAPP(): void {
  useHead({
    link: [
      {
        rel: 'stylesheet',
        id: 'iconfont-css',
        type: 'text/css',
        href: 'https://npm.elemecdn.com/yanyuhexo@1.0.2/ali_post.css'
      },
      {
        rel: 'stylesheet',
        id: 'icons-css',
        type: 'text/css',
        href: 'https://at.alicdn.com/t/c/font_2762112_upcpd3gqyfd.css',
        media: 'all'
      }
    ],
    script: [
      {
        type: 'text/javascript',
        src: 'https://lf9-cdn-tos.bytecdntp.com/cdn/expire-1-M/jquery/3.6.0/jquery.min.js',
        id: 'jquery-core-js'
      },
      {
        type: 'text/javascript',
        src: 'https://lf26-cdn-tos.bytecdntp.com/cdn/expire-1-M/qrcodejs/1.0.0/qrcode.js',
        id: 'qr-code-core-js'
      }
    ]
  })
  /* 样式代码 */
  const styleContent = `color: rgb(30,152,255);margin-bottom: 0.25rem;`
  const webSite = 'https://www.yanyuplus.cn/'
  const content = `
    版 本 号：1.0.8
    编译日期：2024-06-27 23:45:25
    作者介绍：手执烟火以谋生，心怀诗意以谋爱。
    作者博客:  ${webSite}`
  console.log(`%c${content}`, styleContent)
}

async function getSite(): Promise<void> {
  await getSiteConfig().then(({data}: any) => {
    appStore.categoryCount = data.data.categoryCount
    appStore.tagCount = data.data.tagCount
    appStore.commentCount = data.data.commentCount
    appStore.websiteConfig = data.data.websiteConfigDTO
    useHead({
      title: data.data.websiteConfigDTO.name + ' | ' + system.slogan,
      meta: [
        {name: 'description', content: data.data.websiteConfigDTO.description},
        {name: 'keywords', content: data.data.websiteConfigDTO.keyWords}
      ],
      link: [
        {rel: 'icon', type: 'image/x-icon', href: data.data.websiteConfigDTO.favicon}
      ],
      script: [],
      style: [
        {id: 'head-custom-css', type: 'text/css', textContent: data.data.websiteConfigDTO.htmlTag},
        {
          id: 'footer-custom-css',
          type: 'text/css',
          textContent: data.data.websiteConfigDTO.footerCode,
          body: true
        },
      ]
    })
    useSeoMeta({
      ogTitle: data.data.websiteConfigDTO.name,
      ogImage: data.data.websiteConfigDTO.logo,
      ogDescription: data.data.websiteConfigDTO.description
    })
  })
}
</script>
